﻿namespace NMortgage.UI.Tests
{
    using System;

    using Caliburn.Micro;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using NMortgage.UI.Events;
    using NMortgage.UI.Model;
    using NMortgage.UI.ViewModels;

    [TestClass]
    public class FeeListViewModelTest : TestBase<FeeListViewModel>
    {
        #region Methods

        [TestMethod]
        public void Cannot_MoveDown_If_Lowest_One()
        {
            Subject.Handle(new ProfileItemAdded(new Fee()));
            var fee = new Fee();
            Subject.Handle(new ProfileItemAdded(fee));
            var actual = Subject.ItemCollection.CanMoveDown(fee);
            Assert.IsFalse(actual);
        }

        [TestMethod]
        public void Cannot_MoveUp_If_Highest_One()
        {
            var fee = new Fee();
            Subject.Handle(new ProfileItemAdded(fee));
            Subject.Handle(new ProfileItemAdded(new Fee()));
            var actual = Subject.ItemCollection.CanMoveUp(fee);
            Assert.IsFalse(actual);
        }

        [TestMethod]
        public void Can_MoveDown_If_Not_Lowest_One()
        {
            var fee = new Fee();
            Subject.Handle(new ProfileItemAdded(fee));
            Subject.Handle(new ProfileItemAdded(new Fee()));
            var actual = Subject.ItemCollection.CanMoveDown(fee);
            Assert.IsTrue(actual);
        }

        [TestMethod]
        public void Can_MoveUp_If_Not_Highest_One()
        {
            Subject.Handle(new ProfileItemAdded(new Fee()));
            var fee = new Fee();
            Subject.Handle(new ProfileItemAdded(fee));
            var actual = Subject.ItemCollection.CanMoveUp(fee);
            Assert.IsTrue(actual);
        }

        [TestMethod]
        public void Edit_Test()
        {
            var fee = new Fee();
            Subject.Edit(fee);
            Assert.IsNotNull(Subject.ItemDialog);
        }

        [TestMethod]
        public void Handle_Adds_The_Rate_To_List()
        {
            var fee = new Fee();

            Subject.Handle(new ProfileItemAdded(fee));
            var actual = Subject.ItemCollection.Contains(fee);
            Assert.IsTrue(actual);
        }

        [TestMethod]
        public void Handle_CancelEvent()
        {
            var dialog = new FeeViewModel(null);
            Subject.Add();

            Subject.Handle(new CancelEvent(dialog));
            var actual = Subject.ItemDialog;
            Assert.IsNull(actual);
        }

        [TestMethod]
        public void MoveDown()
        {
            var expected = 1;

            var fee = new Fee();
            Subject.Handle(new ProfileItemAdded(fee));
            Subject.Handle(new ProfileItemAdded(new Fee()));

            Subject.MoveDown(fee);
            var actual = Subject.ItemCollection.IndexOf(fee);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void MoveUp()
        {
            var expected = 0;

            Subject.Handle(new ProfileItemAdded(new Fee()));
            var fee = new Fee();
            Subject.Handle(new ProfileItemAdded(fee));
            Subject.MoveUp(fee);
            var actual = Subject.ItemCollection.IndexOf(fee);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void Remove()
        {
            var expected = 0;

            var fee = new Fee();
            Subject.Handle(new ProfileItemAdded(fee));

            Subject.Remove(fee);
            var actual = Subject.ItemCollection.Count;
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void Title_Not_Null()
        {
            string actual = Subject.Title;
            Assert.IsNotNull(actual);
        }

        #endregion Methods
    }
}